package com.uppfind.framework.mybatis.generator.generator.config.converts;

import com.uppfind.framework.mybatis.generator.generator.config.TypeConvert;
import com.uppfind.framework.mybatis.generator.generator.config.rules.DBColumnType;

/**
 * ORACLE 字段类型转换
 * Created by xuliugen on 2017/7/6.
 */
public class OracleTypeConvert implements TypeConvert {

    //TODO 进行具体的转换
    public DBColumnType processTypeConvert(String fieldType) {
        String t = fieldType.toUpperCase();
        if (t.contains("CHAR")) {
            return DBColumnType.ORACLE_STRING;
        } else if (t.contains("DATE") || t.contains("TIMESTAMP")) {
            return DBColumnType.ORACLE_DATE;
        } else if (t.contains("NUMBER")) {
            if (t.matches("NUMBER\\(+\\d\\)")) {
                return DBColumnType.ORACLE_INTEGER;
            } else if (t.matches("NUMBER\\(+\\d{2}+\\)")) {
                return DBColumnType.ORACLE_LONG;
            }
            return DBColumnType.ORACLE_DOUBLE;
        } else if (t.contains("FLOAT")) {
            return DBColumnType.ORACLE_FLOAT;
        } else if (t.contains("binary")) {
            return DBColumnType.ORACLE_BYTE_ARRAY;
        } else if (t.contains("RAW")) {
            return DBColumnType.ORACLE_BYTE_ARRAY;
        }
        return DBColumnType.ORACLE_STRING;
    }

}
